﻿/************************************************************************

  Extended Silverlight Toolkit – SAMPLE CODE

  Copyright (C) 2010-2012 Xceed Software Inc.

  This program is provided to you under the terms of the Microsoft Public
  License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

  Please purchase a commercial version of this toolkit if you are using
  it in a commercial product. The commercial versions support the project,
  and also include more features for each control, priority support,
  source code, updates, removed watermark, and a proprietary license.

  Visit http://xceed.com and follow @datagrid on Twitter.

  **********************************************************************/

using System;
#if SILVERLIGHT
using System.Windows.Browser;
#else
using System.Diagnostics;
#endif
using System.Windows.Controls;
using Xceed.Utils.Silverlight.LiveExplorer;

namespace Xceed.Silverlight.ListBox.Samples
{
  public partial class RemoteDataAccessSettings : UserControl, ISampleSettings
  {
    public RemoteDataAccessSettings()
    {
      InitializeComponent();
    }

    //  This function is necessary to manage button click. The button
    //  is useful because Hyperlink doesn't work the same way in Silverlight vs WPF.
    private void OnHyperlinkButton_Click( object sender, EventArgs e )
    {
      Button button = ( Button )sender;
      string buttonLink = ( string )button.DataContext;

#if SILVERLIGHT
      HtmlPage.PopupWindow( new Uri( buttonLink, UriKind.Absolute ), "_blank", null );
#else
      ProcessStartInfo startInfo = new ProcessStartInfo( buttonLink );
      Process.Start( startInfo );
#endif
    }

    #region ISampleSettings Members

    void ISampleSettings.RegisterSampleHost( ISampleHost sampleHost )
    {
      if( sampleHost != null )
      {
        m_sampleHost = sampleHost.SampleHost as RemoteDataAccessSample;
      }
    }

    void ISampleSettings.UnregisterSampleHost( ISampleHost sampleHost )
    {
      if( sampleHost == null )
        throw new ArgumentNullException( "sampleHost" );

      if( sampleHost.SampleHost == m_sampleHost )
      {
        m_sampleHost = null;
      }
      else
      {
        throw new InvalidOperationException( "An invalid SampleHost is being unregistered." );
      }
    }

    #endregion // ISampleSettings Members

    private RemoteDataAccessSample m_sampleHost;
  }
}
